package com.itfreer.file;

import android.support.test.runner.AndroidJUnit4;

import com.itfreer.file.path.FileUpload;

import org.junit.Test;
import org.junit.runner.RunWith;

import java.io.File;
import java.io.FileInputStream;

@RunWith(AndroidJUnit4.class)
public class PathUploadPathTest {

    @Test
    public void update() {
        String filePath = "/storage/emulated/0/sheng.shp";
        String bucketName = "upload";
        String objectKey = "20180810/sheng.shp";
        FileUpload.instance.putObject(bucketName, objectKey, getByte(filePath));
    }

    private byte[] getByte(String filePath){
        File fileInfo = new File(filePath);
        if (fileInfo.exists()) {
            try {
                FileInputStream in = new FileInputStream(fileInfo);
                byte[] buffer = new byte[in.available()];
                in.read(buffer);
                in.close();
                return buffer;
            } catch (Exception e) {
                e.printStackTrace();
                return null;
            }
        } else {
            return null;
        }
    }
}
